﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Runtime.Serialization;

namespace CMD.BAL.CAT
{
    [DataContractAttribute]
    public class Banco
    {
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string idBanco;
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string dscBanco;
        public static DataTable GetData()
        {
            DataTable dt;
            //ejecutar store
            dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_CAT_SEL_BANCO");
            return dt;
        }
        public static DataTable GetDataIdBanco(string idBanco)
        {
            DataTable dt;
            //ejecutar store
            dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_CAT_SEL_BANCO_WEB'" + idBanco + "'");
            return dt;
        }
        public static List<Banco> GetDataBanco()
        {
            try
            {
                DataTable dt;
                dt = Banco.GetData();
                //DataTable dt = new DataTable();
                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else
                {
                    List<Banco> list = dt.AsEnumerable().Select(
                        row => new Banco
                        {
                            idBanco = String.IsNullOrEmpty(row.Field<string>("ID_BANCO"))
                            ? ""
                            : row.Field<string>("ID_BANCO"),
                            dscBanco = String.IsNullOrEmpty(row.Field<string>("DSC_BANCO"))
                            ? ""
                            : row.Field<string>("DSC_BANCO"),
                        }
                        ).ToList();
                    return list;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static Banco GetDataDscBanco(string idBanco)
        {
            try
            {
                Banco ban;
                DataTable dt = Banco.GetDataIdBanco(idBanco);
                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else if (idBanco == null)
                {
                    return null;
                }
                else
                {
                    ban = new Banco(null, Convert.ToString(dt.Rows[0]["datBnc_dscBanc"]));
                }
                return ban;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public Banco()
        {
            idBanco = "";
            dscBanco = "";
        }
        public Banco(string idBanco, string dscBanco)
        {
            this.idBanco = idBanco;
            this.dscBanco = dscBanco;
        }
    }
}
